#!/bin/bash
PROJECT=springcloud-oowoo-rocketmq-console
LOGIN_USER=$1
LOGIN_PWD=$2
NOW_TIME=`date +%m%d%H%M`
GIT_REVISION=`git log -1 --pretty=format:"%h"`
IMAGE_TAG=${NOW_TIME}_${GIT_REVISION}
IMAGE_NAME=zhangbin002/${PROJECT}

#执行dockerfile制作镜像
function build_dockerfile(){
    sudo docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
}
#推送镜像文件到私有仓库
function push_image_to_tencent(){
    login_contailer
    tag
    push
}
#登录私有容器服务
function login_contailer(){
    sudo docker login --username=${LOGIN_USER} --password=${LOGIN_PWD}
}
#给镜像打标签
function tag(){
   sudo docker tag ${IMAGE_NAME}:${IMAGE_TAG}  ${IMAGE_NAME}:latest
}
#推送镜像到私有镜像仓库
function push(){
    sudo docker push ${IMAGE_NAME}:latest
}
#开始执行
build_dockerfile
push_image_to_tencent
